package com.cn.goodsadmin.dao.impl;

import com.cn.goodsadmin.common.PageQueryResult;
import com.cn.goodsadmin.dao.BaseDao;
import com.cn.goodsadmin.dao.DestDTO;
import com.cn.goodsadmin.dao.IPanicLogDao;
import com.cn.goodsadmin.po.PanicLog;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository("PanicLogDaoImpl")
public class PanicLogDaoImpl extends BaseDao<PanicLog> implements IPanicLogDao {
    @Override
    public List<PanicLog> findPanicLogByStatus(int status, String gid) throws Exception {
        return null;
    }

    @Override
    public List<PanicLog> findPanicLogByPid(String pid, String openid, Integer appid) throws Exception {
        StringBuilder builder=new StringBuilder();
        builder.append("from PanicLog p where 1=1");
        List<Object> paraList=new ArrayList<Object>();
        int index=0;
        if(pid!=null){
            builder.append(" and p.cPid=?0");
            paraList.add(pid);
            index++;
        }
        if(openid!=null){
            builder.append(" and p.cOpenid=?"+index);
            paraList.add(openid);
            index++;
        }
        if(appid!=null){
            builder.append(" and p.cAppid=?"+index);
            paraList.add(appid);
            index++;
        }
        return find(builder.toString(),paraList.toArray());
    }

    @Override
    public PageQueryResult<DestDTO> findPanicLog(int pageindex, int pagesize, int appid, Integer type, int state) throws Exception {
        StringBuilder builder=new StringBuilder();
        builder.append("from PanicLog p where 1=1");
        List<Object> paraList=new ArrayList<Object>();
        builder.append(" and p.cAppid=?0");
        paraList.add(appid);
        builder.append(" and p.cStatus=?1");
        paraList.add((byte)state);
        if(type!=null){
            builder.append(" and p.cType=?2");
            paraList.add(type.byteValue());
        }
        builder.append("  order by p.cMtime desc");
        return commonQuery(builder.toString(),paraList.toArray(),pageindex,pagesize,DestDTO.class);
    }
}
